Make key selection method configurable in EPA.
authorAleksandr Vityazev <avityazev@disroot.org>
Thu, 15 Feb 2024 19:51:24 +0000 (22:51 +0300)
committerEli Zaretskii <eliz@gnu.org>
Sat, 17 Feb 2024 09:27:09 +0000 (11:27 +0200)
* lisp/epa.el (epa-keys-select-method): New defcustom.
(epa--select-keys-in-minibuffer): New function.
(epa-select-keys): Use new option and function.
* etc/NEWS: Announce it.
* doc/misc/epa.texi (Key Management): Document it.
(Bug#69133)

doc/misc/epa.texi
etc/NEWS
lisp/epa.el

index 27a9e2b0ebbe812bcb6406e0367b84c326b9de1f..cd6da1dadba975f55a20be6265e6c421daac07db 100644 (file)
@@ -289,6 +289,13 @@ also ask you whether or not to sign the text before encryption and if
 you answered yes, it will let you select the signing keys.
 @end deffn
 
+You can change the default method that is used to select keys with the
+variable @code{epa-file-select-keys}.
+
+@defvar epa-keys-select-method
+Method used to select keys in @code{epa-select-keys}.
+@end defvar
+
 @node Cryptographic operations on files
 @section Cryptographic Operations on Files
 @cindex cryptographic operations on files
index 5220a7fb337aa5d6abd608b3e3f48a90e4b548d2..4477116248e2c5a0fc8b6496926297b2dd5f15a6 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1365,6 +1365,14 @@ The new user option 'ielm-history-file-name' is the name of the file
 where IELM input history will be saved.  Customize it to nil to revert
 to the old behavior of not remembering input history between sessions.
 
+** EasyPG
+
++++
+*** New user option 'epa-keys-select-method'.
+This allows the user to customize the key selection method, which can be
+either by using a pop-up buffer or from the minibuffer.  The pop-up
+buffer method is the default, which preserves previous behavior.
+
 \f
 * New Modes and Packages in Emacs 30.1
 
index 53da3bf6cce7e7db70d70b08e779495617665e76..b2593bc62baa12d1a0dcf93f7ff97283a05ce89d 100644 (file)
@@ -73,6 +73,16 @@ The command `epa-mail-encrypt' uses this."
   :group 'epa
   :version "24.4")
 
+(defcustom epa-keys-select-method 'buffer
+  "Method used to select keys in `epa-select-keys'.
+If the value is \\='buffer, the default, keys are selected via a
+pop-up buffer.  If the value is \\='minibuffer, keys are selected
+via the minibuffer instead, using `completing-read-multiple'."
+  :type '(choice (const :tag "Read keys from a pop-up buffer" buffer)
+                (const :tag "Read keys from minibuffer" minibuffer))
+  :group 'epa
+  :version "30.1")
+
 ;;; Faces
 
 (defgroup epa-faces nil
@@ -450,6 +460,25 @@ q  trust status questionable.  -  trust status unspecified.
            (epa--marked-keys))
         (kill-buffer epa-keys-buffer)))))
 
+(defun epa--select-keys-in-minibuffer (prompt keys)
+  (let* ((prompt (pcase-let ((`(,first ,second ,third)
+                              (string-split prompt "\\."))
+                             (hint "(separated by comma)"))
+                   (if third
+                       (format "%s %s. %s: " first hint second)
+                     (format "%s %s: " first hint))))
+         (keys-alist
+          (seq-map
+           (lambda (key)
+             (cons (substring-no-properties
+                    (epa--button-key-text key))
+                   key))
+           keys))
+         (selected-keys (completing-read-multiple prompt keys-alist)))
+    (seq-map
+     (lambda (key) (cdr (assoc key keys-alist)))
+     selected-keys)))
+
 ;;;###autoload
 (defun epa-select-keys (context prompt &optional names secret)
   "Display a user's keyring and ask him to select keys.
@@ -459,7 +488,9 @@ NAMES is a list of strings to be matched with keys.  If it is nil, all
 the keys are listed.
 If SECRET is non-nil, list secret keys instead of public keys."
   (let ((keys (epg-list-keys context names secret)))
-    (epa--select-keys prompt keys)))
+    (pcase epa-keys-select-method
+      ('minibuffer (epa--select-keys-in-minibuffer prompt keys))
+      (_ (epa--select-keys prompt keys)))))
 
 ;;;; Key Details